﻿
using additem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace additem.Controllers
{
    public class PersonController : Controller
    {
        //
        // GET: /Person/
        PersonDataContext data = new PersonDataContext();
        public ActionResult Index()
        {
            PersonDataContext data = new PersonDataContext();
            var peron = (from m in data.Tables select m).ToList();

            return View(peron);
        }
        public ActionResult Create()
        {
            return View();

        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude = "PersonID")] Table person)
        {
            //map data back to dictionary

            if (!ModelState.IsValid)
                return View();
            
            try
            {
                data.Tables.InsertOnSubmit(person);
                data.SubmitChanges();
                return View();
            }
            catch (Exception)
            {
                return View();
            }
           
        }

        public ActionResult Create1()
        {
            return View();

        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create1([Bind(Exclude = "PersonID")] Table1 person)
        {
            
            if (!ModelState.IsValid)
                return View();
            try
            {
                data.Table1s.InsertOnSubmit(person);
                data.SubmitChanges();
                return View();
            }
            catch (Exception)
            {
                return View();
            }

        }
        public ActionResult Edit(int personid)
        {
            var persons = data.Tables.SingleOrDefault(x => x.PersonID == personid);

            return View(persons);
           

        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int personid, Table person)
        {
            var persons = data.Tables.SingleOrDefault(x => x.PersonID == personid);

            UpdateModel(persons);

            data.SubmitChanges();
            return View();
        }


    }
}
